﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProDivingAdmin2salmon14
{ 
    public class FormMainPresenter
    {
        public IFormMain viewFormMain;
        public IStartUpForm viewStartupForm;
        public IDiverForm viewDiverForm;
        public IAddDataForm viewAddDataForm;
        public IContestData modelContestData;
        public IContest modelContest;
        public IDiverList modelDiverList;
        public IJudgeForm viewJudgeForm;

        public FormMainPresenter(IFormMain viewFormMain, IStartUpForm viewStartupForm, IDiverForm viewDiverForm, IAddDataForm viewAddDataForm, IJudgeForm viewJudgeForm, ContestData modelContestData, Contest modelContest, DiverList modelDiverList) 
        {
            this.viewFormMain = viewFormMain;
            this.viewStartupForm = viewStartupForm;
            this.viewDiverForm = viewDiverForm;
            this.viewAddDataForm = viewAddDataForm;
            this.viewJudgeForm = viewJudgeForm;
            this.modelContestData = modelContestData;
            this.modelContest = modelContest;
            this.modelDiverList = modelDiverList;

            this.modelContest.EventShowJudgeForm += ShowJudgeForm;
            this.viewFormMain.EventNextDive += NextDive;
            this.viewFormMain.EventDQDiver += DQDiver;
            this.viewFormMain.EventGetNextDiver += NextDiver;
            this.viewFormMain.EventGetCurrentDiver += CurrentDiver;
            this.viewFormMain.EventGetDiverList += GetDiverList;
            this.viewFormMain.EventGetCurrentDive += GetCurrentDive;
            this.viewFormMain.EventGetAmountOfJudges += GetAmountOfJudges;
            this.viewFormMain.EventGetConnectedJudgeList += GetConnectedJudgeList;
            this.viewFormMain.EventGetDiverOrder += GetDiverOrder;
            this.viewFormMain.EventGetIsNextDive += GetIsNextDive;
            this.viewFormMain.EventGetIsDone += GetIsDone;
            this.viewFormMain.EventGetDiveOrderCounter += GetDiveOrderCounter;
            this.viewFormMain.EventDiveOrderCounterIncrement += DiveOrderCounterIncrement;
            this.viewFormMain.EventResetConnectedJudgesScore += ResetConnectedJudgesScore;

            this.viewFormMain.EventSendDive += SendDive;

            this.viewFormMain.EventCalculateScore += CalculateScore;
            this.viewFormMain.EventCalculateAllDivers += CalculateAllDivers;

            this.viewFormMain.EventResetData += EventResetData;

            this.viewFormMain.EventGetIsFemaleData += GetIsFemale;
            this.viewFormMain.EventGetMinAge += GetMinAge;
            this.viewFormMain.EventGetDivingHeight += GetDivingHeight;
            this.viewFormMain.EventGetJudges += GetJudges;
            this.viewFormMain.EventGetJudgesPath += GetJudgesPath;
            this.viewFormMain.EventGetDiversPath += GetDiversPath;
            this.viewFormMain.EventBroadcastIP += BroadcastIP;

            this.viewStartupForm.EventSetIsFemale += SetIsFemale;
            this.viewStartupForm.EventSetMinAge += SetMinAge;
            this.viewStartupForm.EventSetDivingHeight += SetDivingHeight;
            this.viewStartupForm.EventSetJudges += SetJudges;
            this.viewStartupForm.EventSetJudgesPath += SetJudgesPath;
            this.viewStartupForm.EventSetDiversPath += SetDiversPath;
            this.viewStartupForm.EventSetContestName += SetContestName;

            this.viewDiverForm.EventGetListOfDivers += GetListOfDivers;

            this.viewDiverForm.EventDisqualifyDiver += DisqualifyDiver;
            this.viewDiverForm.EventMarkDiverAsInjured += MarkDiverAsInjured;

            this.viewJudgeForm.EventGetJudgeList += GetJudgeList;
            this.viewJudgeForm.EventAddJudgeToList += AddJudgeToList;
            this.viewJudgeForm.EventGetAmountOfJudges += GetAmountOfJudges;
            this.viewJudgeForm.EventDeleteJudgeFromList += DeleteJudgeFromList;
            this.viewJudgeForm.EventEditJudge += EditJudge;
            this.viewJudgeForm.EventSetAmountOfJudges += SetAmountOfJudges;
            this.viewJudgeForm.EventSaveJudges += SaveJudges;
            this.viewJudgeForm.EventReorderJudgeList += ReorderJudgeList;

            this.viewAddDataForm.EventAddDiverToList += AddDiverToList;
            this.viewAddDataForm.EventAddDiveToDiver += AddDiveToDiver;
            this.viewAddDataForm.EventGetDiveListFromDiver += GetDiveListFromDiver;
            this.viewAddDataForm.EventGetDiveName += GetDiveName;
            this.viewAddDataForm.EventDeleteDiver += DeleteDiver;
            this.viewAddDataForm.EventDeleteDiveFromDiver += DeleteDiveFromDiver;
            this.viewAddDataForm.EventGetNewDiverList += GetNewDiverList;
            this.viewAddDataForm.EventSaveDivers += SaveDivers;
            this.viewAddDataForm.EventGetAmountOfDives += GetAmountOfDives;
            this.viewAddDataForm.EventEditDiver += EditDiver;
            this.viewAddDataForm.EventEditDiveToDiver += EditDiveToDiver;
            this.viewAddDataForm.EventLoadDiverList += LoadDiverList;

            this.viewFormMain.EventSetFilePath += SetFilePath;
            this.viewFormMain.EventGetFilePath += GetFilePath;
            this.viewFormMain.EventGetContest += GetContest;
            this.viewFormMain.EventSaveContest += SaveContest;
            this.viewFormMain.EventLoadContest += LoadContest;
            this.viewFormMain.EventSetContest += SetContest;
            this.viewFormMain.EventGetContestName += GetContestName;
            this.viewFormMain.EventGetJudgeList += GetJudgeList;

            this.viewFormMain.EventGetJudgeIDs += GetJudgeIDs;
        }

        private void ShowJudgeForm()
        {
            this.viewFormMain.ShowJudgeForm();
        }

        private void ReorderJudgeList()
        {
            this.modelContest.ReorderJudgeList();
        }

        private void SaveJudges(string filePath, List<Judge> judgeList)
        {
            FileManager.SaveJudges(filePath, judgeList);
        }

        private void SetAmountOfJudges(int amountOfJudges)
        {
            this.modelContest.SetAmountOfJudges(amountOfJudges);
        }

        private void EditJudge(int judgeIndex, Judge newJudge)
        {
            this.modelContest.EditJudge(judgeIndex, newJudge);
        }

        private DiverList LoadDiverList(string filePath)
        {
            return FileManager.LoadDiverList(filePath);
        }

        private void DeleteJudgeFromList(int id)
        {
            this.modelContest.DeleteJudgeFromList(id);
        }

        private void AddJudgeToList(Judge judge)
        {
            Contest.judgeList.Add(judge);
            this.modelContest.BackupJudgeList();
        }

        private List<Judge> GetJudgeList()
        {
            return this.modelContest.GetJudgeList();
        }

        private string GetContestName()
        {
            return this.modelContest.GetContestName();
        }

        private void SetContestName(string contestName)
        {
            this.modelContest.SetContestName(contestName);
        }

        private void ResetConnectedJudgesScore()
        {
            this.modelContest.ResetConnectedJudgesScore();
        }

        private string GetFilePath()
        {
            return this.modelContest.GetFilePath();
        }

        private void SetFilePath(string filePath)
        {
            this.modelContest.SetFilePath(filePath);
        }

        private void DiveOrderCounterIncrement()
        {
            this.modelContest.DiveOrderCounterIncrement();
        }

        private int GetDiveOrderCounter()
        {
            return this.modelContest.GetDiveOrderCounter();
        }

        private void DeleteDiver(int diverIndx)
        {
            ((DiverList)this.modelDiverList).DeleteDiver(diverIndx);
        }

        private void GetJudgeIDs(string[] ids)
        {
            this.modelContest.GetJudgeIDs(ids);
        }

        private void BroadcastIP()
        {
            CommunicationServer.BroadCastIP();
        }

        private void EditDiveToDiver(Diver diver, Dive newDive, int diveIndx)
        {
            this.modelContest.EditDiveToDiver(diver, newDive, diveIndx);
        }

        private void EditDiver(int diverIndx, Diver newDiver)
        {
            this.modelContest.EditDiver(diverIndx, newDiver);
        }

        private int GetAmountOfDives()
        {
            return this.modelContest.GetAmountOfDives();
        }

        private void SetContest(Contest contest)
        {
            this.modelContest = contest;
            this.modelDiverList = this.modelContest.GetDiverList();
        }

        private Contest LoadContest(string filePath)
        {
            return FileManager.LoadContest(filePath);
        }

        private Contest GetContest()
        {
            return (Contest)this.modelContest;
        }

        private void SaveContest(string filePath, Contest contest)
        {
            FileManager.SaveContest(filePath, contest);
        }

        private void SaveDivers(DiverList diverList, string filePath)
        {
            FileManager.SaveDivers(diverList, filePath);
        }

        private DiverList GetNewDiverList()
        {
            return this.modelContest.GetDiverList();
        }

        private void DeleteDiveFromDiver(Diver diver, int index)
        {
            this.modelContest.DeleteDiveFromDiver(diver, index);
        }

        private string GetDiveName(string diveCode)
        {
            return FileManager.GetDiveName(diveCode);
        }

        private void AddDiverToList(Diver diver)
        {
            this.modelContest.AddDiverToList(diver);
        }

        private void AddDiveToDiver(Diver diver, Dive dive)
        {
            this.modelContest.AddDiveToDiver(diver, dive);
        }

        private List<Dive> GetDiveListFromDiver(Diver diver)
        {
            return this.modelContest.GetDiveListFromDiver(diver);
        }

        private void MarkDiverAsInjured(Diver diver)
        {
            this.modelDiverList.MarkDiverAsInjured(diver);
        }

        private void DisqualifyDiver(Diver diver)
        {
            this.modelDiverList.DisqualifyDiver(diver);
        }

        private DiverList GetListOfDivers()
        {
            return this.modelContest.GetListOfDivers();
        }

        private bool GetIsDone()
        {
            return this.modelContest.GetIsDone();
        }

        private bool GetIsNextDive()
        {
            return this.modelContest.GetIsNextDive();
        }

        private void SendDive(string diveCode)
        {
            CommunicationServer.SendDive(diveCode);
        }

        private List<DisplayDive> GetDiverOrder()
        {
            return this.modelContest.GetDiverOrder();
        }

        private List<Judge> GetConnectedJudgeList()
        {
            return this.modelContest.GetConnectedJudgeList();
        }

        private int GetAmountOfJudges()
        {
            return this.modelContest.GetAmountOfJudges();
        }

        void EventResetData(bool female, int minAge, int divingHeight, int judges, string diversPath, string judgesPath, string filePath)
        {
            this.modelContest.ResetData(female, minAge, divingHeight, judges, diversPath, judgesPath, filePath);
            this.modelDiverList = this.modelContest.GetDiverList();
        }

        private int GetCurrentDive() 
        {
            return this.modelContest.GetCurrentDive();
        }

        private void NextDive()
        {
            this.modelContest.NextDive();
        }

        private void DQDiver(Diver diver) 
        {
            diver.isDisqualified = true;
            this.modelContest.DQDiver(diver);
        }

        private Diver NextDiver() 
        {
            return this.modelContest.GetNextDiver();
        }

        private Diver CurrentDiver() 
        {
            return this.modelContest.GetCurrentDiver();
        }

        private DiverList GetDiverList() 
        {
            return this.modelContest.GetDiverList();
        }

        private void CalculateScore(Diver diver) 
        {
            this.modelDiverList.CalculateScore(diver);
        }

        private void CalculateAllDivers() 
        {
            this.modelDiverList.CalculateAllDivers();
        }

        private string GetDiversPath()
        {
            return this.modelContestData.GetDiversPath();
        }

        private string GetJudgesPath()
        {
            return this.modelContestData.GetJudgesPath();
        }

        private int GetJudges()
        {
            return this.modelContestData.GetJudges();
        }

        private int GetDivingHeight()
        {
            return this.modelContestData.GetDivingHeight();
        }

        private int GetMinAge()
        {
            return this.modelContestData.GetMinAge();
        }

        private bool GetIsFemale()
        {
            return this.modelContestData.GetIsFemaleData();
        }

        private void SetDiversPath(string diversPath)
        {
            this.modelContestData.SetDiversPath(diversPath);
        }

        private void SetJudgesPath(string judgesPath)
        {
            this.modelContestData.SetJudgesPath(judgesPath);
        }

        private void SetJudges(int judges)
        {
            this.modelContestData.SetJudges(judges);
        }

        private void SetDivingHeight(int divingHeight)
        {
            this.modelContestData.SetDivingHeight(divingHeight);
        }

        private void SetMinAge(int minAge)
        {
            this.modelContestData.SetMinAge(minAge);
        }

        private void SetIsFemale(bool isFemale)
        {
            this.modelContestData.SetIsFemaleData(isFemale);
        }
    }
}
